package com.heima.admin.controller.v1;

import com.heima.common.exception.CostomException;
import com.heima.model.admin.dtos.ChannelDto;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;

import com.heima.admin.service.AdChannelService;
import com.heima.model.common.enums.AppHttpCodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 胡慧
 * @title: AdChannelController
 * @projectName heima-leadnews
 * @description: TODO
 * @date 2021/2/420:37
 */
@RestController
@RequestMapping("/api/v1/channel")
@Api(value = "频道管理",tags ="channel",description = "管理频道API")
public class AdChannelController {

    @Autowired
    private AdChannelService channelService;

    @PostMapping("/list")
    @ApiOperation("频道分页列表查询")
    public ResponseResult findByNameAndPage(@RequestBody ChannelDto dto){
        return channelService.findByNameAndPage(dto);
    }
    /**
     * 添加数据
     */
    @PostMapping("/save")
    @ApiOperation("频道列表添加")
    public ResponseResult insert(@RequestBody AdChannel channel){
        return channelService.insert(channel);
    }
    @PostMapping("/update")
    @ApiOperation("频道列表修改")
    public ResponseResult edit(@RequestBody AdChannel channel){
        return channelService.edit(channel);
    }
    @GetMapping("/del/{id}")
    @ApiOperation("频道列表删除")
    public ResponseResult delete(@PathVariable("id") Integer id){

        return channelService.delete(id);
    }
    @GetMapping("/channels")
    public ResponseResult findAll() {

        List<AdChannel> list = channelService.list();
        return ResponseResult.okResult(list);
    }
}
